@extends('admin.layouts.head')
@section('content')
<body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item active" aria-current="page">用户列表</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="statistics-container">
                                    <div class="row">
                                        <div class="col-md-3">
                                            <label>所有用户乐游币累计数值: </label><span>{{ $totalLyBalance }}元</span>
                                        </div>
                                        <div class="col-md-3">
                                            <label>近30日活跃人群乐游币累计数值: </label><span>{{ $recent30DayLyBalance }}元</span>
                                        </div>
                                        <!--<div class="col-md-4">-->
                                        <!--    <label>当日乐游币充值金额: </label><span>{{ $todayRechargeLyBalance }}</span>-->
                                        <!--</div>-->
                                        <div class="col-md-2">
                                            <label>当日真实充值金额: </label><span>{{ $todayRealRechargeMoney }}元</span>
                                        </div>
                                        <div class="col-md-2">
                                            <label>进入充值额外赠送乐游币: </label><span>{{ $todayExtraRechargeLyBalance }}元</span>
                                        </div>
                                        <div class="col-md-2">
                                            <label>今日兑换乐游币: </label><span>{{ $todayExchangeLyBalance }}元</span>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-2">
                                            <label>积分≥50的用户数: </label><span>{{ $integralStats->usersWithAtLeast50 }}</span>
                                        </div>
                                        <div class="col-md-2">
                                            <label>能抽10次（积分≥500）的用户数: </label><span>{{ $integralStats->canDraw10Times }}</span>
                                        </div>
                                        <div class="col-md-2">
                                            <label>能抽20次（积分≥1000）的用户数: </label><span>{{ $integralStats->canDraw20Times }}</span>
                                        </div>
                                        <div class="col-md-3">
                                            <label>能抽50次（积分≥2500）的用户数: </label><span>{{ $integralStats->canDraw50Times }}</span>
                                        </div>
                                        <div class="col-md-3">
                                            <label>能抽100次（积分≥5000）的用户数: </label><span>{{ $integralStats->canDraw100Times }}</span>
                                        </div>

                                    </div>
                                </div>

                                <div class="form-group mt-4">
                                    <div class="row">
                                        <div class="col-lg-2 col-md-2" style="margin-bottom: 10px">
                                            <a href="{{route('admin.users.create')}}" class="btn btn-primary"> 添加 </a>
                                            <a href="javascript:void(0);" class="btn btn-danger" onclick="operation_tip2(-1)"> 批量删除 </a>
                                        </div>
                                        <div class="col-lg-10 col-md-10">
                                            <div class="input-group" style="width: 1200px;">
                                                <input type="text" class="form-control" id="search" value="{{$_GET['search'] ?? ''}}" placeholder="搜索..." />
                                                <select class="form-control" id="last_login_time">
                                                    <option value="0" @if (empty($_GET['last_login_time']) || $_GET['last_login_time'] == 0) selected @endif >不限登录时间</option>
                                                    <option value="1" @if (!empty($_GET['last_login_time']) && $_GET['last_login_time'] == 1) selected @endif >15-30天</option>
                                                    <option value="2" @if (!empty($_GET['last_login_time']) && $_GET['last_login_time'] == 2) selected @endif >31-60天</option>
                                                    <option value="3" @if (!empty($_GET['last_login_time']) && $_GET['last_login_time'] == 3) selected @endif >60天以上</option>
                                                </select>
                                                <select class="form-control" id="level_sel">
                                                    <option value="0" @if (empty($_GET['level_id']) || $_GET['level_id'] == 0) selected @endif >全部等级</option>
                                                    @foreach($levelMap as $id => $l)
                                                        <option value="{{$id}}" @if (!empty($_GET['level_id']) && $_GET['level_id'] == $id) selected @endif >{{$l}}</option>
                                                    @endforeach
                                                </select>
                                                <input type="text" class="form-control" id="birthday" value="{{$_GET['birthday'] ?? ''}}" placeholder="生日" />
                                                <button class="btn btn-primary"
                                                        onclick="window.location.href = '{{ route('admin.users.index') }}?search='+$('#search').val()+'&last_login_time='+$('#last_login_time option:selected').val()+'&level_id='+$('#level_sel option:selected').val()+'&sort={{ request('sort', 'ly_balance') }}&order={{ request('order', 'desc') }}&birthday='+$('#birthday').val()">
                                                    搜索
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="table-responsive">
                                    <table class="table table-sm table-hover text-center">
                                        <thead>
                                        <tr>
                                            <th>
                                                <div class="custom-control custom-checkbox">
                                                    <input type="checkbox" class="custom-control-input" name="selectAll" id="selectAll">
                                                    <label class="custom-control-label" for="selectAll"></label>
                                                </div>
                                            </th>
                                            <th style="min-width:50px;">ID</th>
                                            <th style="min-width:125px;">openid</th>
                                            <th style="min-width:50px;">等级</th>
                                            <th style="min-width:80px;">
                                                <a href="{{ route('admin.users.index', array_merge(request()->query(), ['sort' => 'total_recharge', 'order' => request('order', 'desc') == 'asc' ? 'desc' : 'asc'])) }}">
                                                    成长值
                                                    @if (request('sort') == 'total_recharge')
                                                        @if (request('order') == 'asc')
                                                            ▲
                                                        @else
                                                            ▼
                                                        @endif
                                                    @endif
                                                </a>
                                            </th>
                                             <th style="min-width:100px;">微信名称</th>
                                            <th style="min-width:120px;">手机号</th>
                                            <th style="min-width:60px;">
                                                <a href="{{ route('admin.users.index', array_merge(request()->query(), ['sort' => 'ly_balance', 'order' => request('order', 'desc') == 'asc' ? 'desc' : 'asc'])) }}">
                                                    乐游币
                                                    @if (request('sort') == 'ly_balance')
                                                        @if (request('order') == 'asc')
                                                            ▲
                                                        @else
                                                            ▼
                                                        @endif
                                                    @endif
                                                </a>
                                            </th>
                                            <th style="min-width:80px;">商城积分</th>
                                            <th style="min-width:80px;">玩服积分</th>
                                            <th style="min-width:80px;">新红包币</th>
                                             <th style="min-width:140px;">创建时间</th>
                                            <th style="min-width:140px;">
                                                <a href="{{ route('admin.users.index', array_merge(request()->query(), ['sort' => 'game_login_time', 'order' => request('order', 'desc') == 'asc' ? 'desc' : 'asc'])) }}">
                                                    最后登录时间
                                                    @if (request('sort') == 'game_login_time')
                                                        @if (request('order') == 'asc')
                                                            ▲
                                                        @else
                                                            ▼
                                                        @endif
                                                    @endif
                                                </a>
                                            </th>

                                            @if (isSuperAdmin())
                                                <th style="min-width:140px;">生日</th>
                                                <th style="min-width:50px;">专属客服</th>
                                            @endif
                                            <th style="min-width:800px;">操作</th>


                                            <th style="min-width:80px;">qq号</th>
                                            <th style="min-width:80px;">微信账号</th>
                                            <th style="min-width:100px;">真实姓名</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($usersData as $key => $data)
                                            <tr>
                                                <td>
                                                    <div class="custom-control custom-checkbox">
                                                        <input type="checkbox" class="custom-control-input" name="checkboxVal" id="{{$data->id}}" value="{{$data->id}}">
                                                        <label class="custom-control-label" for="{{$data->id}}"></label>
                                                    </div>
                                                </td>
                                                 <td>{{($usersData->currentPage()-1)*15+1+$key}}</td>
                                                <td>{{$data->unionid}}</td>
                                                <td>{{$levelMap[$data->level_id] ?? '-'}}</td>
                                                <td>{{$data->total_recharge}}</td>
                                                <td>{{$data->username}}</td>
                                                <td>{{$data->mobile}}</td>
                                                <td>{{$data->ly_balance}}</td>
                                                <td>{{$data->integral}}</td>
                                                <td>{{$data->wf_integral}}</td>
                                                <td>{{$data->new_red_packet_coin}}</td>
                                                <td>{{ $data->created_at }}</td>
                                                <td>{{ $data->game_login_time }}</td>
                                                @if (isSuperAdmin())
                                                    <td>{{$data->birthday}}</td>
                                                    <td>{{$data->kf_name}}</td>
                                                @endif
                                                <td>
                                                    @if (isSuperAdmin())
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=newRedPacketCoin" class="btn btn-primary btn-sm">修改新红包币</a>
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=ly" class="btn btn-primary btn-sm">修改乐游币</a>
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=red" class="btn btn-primary btn-sm">修改推广红包币</a>
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=total" class="btn btn-primary btn-sm">修改累计积分</a>
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=jf" class="btn btn-primary btn-sm">修改积分</a>
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=wf" class="btn btn-primary btn-sm">修改玩服积分</a>
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=mobile" class="btn btn-primary btn-sm">修改手机</a>
                                                    <a href="javascript:void(0);" class="btn btn-danger btn-sm" onclick="operation_tip2({{$data->id}})">删除</a>
                                                    @endif
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=birthday" class="btn btn-primary btn-sm">修改生日</a>
                                                    <a href="/admin/users/showSetBalance/{{$data->id}}?type=relatedInfo" class="btn btn-primary btn-sm">添加关联信息</a>
                                                    <a href="/admin/users/showBalanceLog?union_id={{$data->unionid}}" class="btn btn-primary btn-sm">余额记录</a>
                                                    <a href="/admin/recharge/gameRechargeListPage?union_id={{$data->unionid}}" class="btn btn-primary btn-sm">充值兑换记录</a>
                                                    <a href="javascript:;" class="btn btn-primary btn-sm" onclick="showInviteeUser({{$data->id}})">邀请记录</a>
                                                </td>


                                                <td>{{$data->qq}}</td>
                                                <td>{{$data->wx_account}}</td>
                                                <td>{{$data->name}}</td>
                                            </tr>
                                        @endforeach
                                        </tbody>
                                    </table>
                                </div>

                            </div> <!-- .card-body -->

                            <!-- 分页 -->
                            <nav class="page-card-pagination">
                                <ul class="pagination justify-content-center">
                                    {{$usersData->Links()}}
                                </ul>
                            </nav>
                            <!-- end分页 -->

                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <style>
        .selected-row {
            background-color: #f5f5f5;
        }
        .statistics-container {
            padding: 20px;
            background-color: #f9f9f9;
            margin-bottom: 20px;
            border-radius: 5px;
        }
        .statistics-container label {
            font-weight: bold;
            margin-right: 10px;
        }
        .statistics-container span {
            color: #007bff;
        }
    </style>
    <script>
        // 全选
        $('input[name="selectAll"]').on("click", function() {
            if ($(this).is(':checked')) {
                $('input[name="checkboxVal"]').each(function() {
                    $(this).prop("checked", true);
                    $(this).closest('tr').addClass('selected-row');
                });
            } else {
                $('input[name="checkboxVal"]').each(function() {
                    $(this).prop("checked", false);
                    $(this).closest('tr').removeClass('selected-row');
                });
            }
        });

        // 单选高亮
        $('input[name="checkboxVal"]').on("click", function() {
            if ($(this).is(':checked')) {
                $(this).closest('tr').addClass('selected-row');
            } else {
                $(this).closest('tr').removeClass('selected-row');
            }
        });

        let isLoading = false;

        //删除
        function submit(id) {
            obj = document.getElementsByName("checkboxVal");
            check_val = [];
            for (k in obj) {
                if (obj[k].checked) {
                    check_val.push(obj[k].value);
                }
            }

            var checkboxVal;
            if (id === -1) {
                checkboxVal = check_val;
            } else {
                checkboxVal = id;
            }

            if (checkboxVal == '') {
                toast('您还没有选择要删除的对象。');
                return false;
            }

            if (isLoading === false) {
                isLoading = true;

                axios.delete('{{route('admin.users.destroy','').'/'}}' + checkboxVal)
                    .then(function(response) {
                        isLoading = false;
                        toast_tip2(response.data.message, window.location.href);
                    })
                    .catch(function(error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function(index, object) {
                            toast(object[0]);
                            return false;
                        });
                    });
            }
        }

        function showInviteeUser(id) {
            layer.open({
                type: 2,
                title: "邀请列表",
                content: "/admin/users/getInviteeUser?id=" + id,
                area: ['810px', '600px']
            });
        }
    </script>
</body>
@endsection
